﻿using Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dal
{
    public class EmployeeDal
    {
        public EmployeeDal(BabyfaceEntities _db)
        {
            db = _db;
        }
        private BabyfaceEntities db { get; set; }

        public int Add(Employee entity)
        {
            db.Employee.Add(entity);
            db.SaveChanges();

            return entity.EmployeeId;
        }

        public int Edit(Employee entity)
        {
            db.Employee.Attach(entity);
            db.Entry(entity).State = EntityState.Modified;
            return db.SaveChanges();
        }

        public int Delete(int id)
        {
            var entity = new Employee { EmployeeId = id };
            db.Employee.Attach(entity);
            db.Employee.Remove(entity);
            return db.SaveChanges();
        }

        public Employee GetById(int id)
        {
            var entity = db.Employee.Where(w => w.EmployeeId == id).FirstOrDefault();
            return entity;
        }

        public IList<Employee> GetAll()
        {
            var list = db.Employee.ToList();
            return list;
        }


    }
}
